package cn.dxs.adt.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.dxs.adt.R;
import cn.dxs.adt.bean.Icon;

public class IconAdapter extends BaseAdapter {

    private Context mContext;
    private List<Icon> mList;

    public IconAdapter(Context context, List<Icon> list){
        this.mContext = context;
        this.mList = list;
    }

    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public Object getItem(int position) {
        if (mList != null && mList.size() > position) {
            return mList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder mViewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_grid_icon, null);
            mViewHolder = getViewHolder(convertView);
        } else {
            mViewHolder = (ViewHolder) convertView.getTag();
        }
        setData(position, mViewHolder);
        return convertView;
    }

    private ViewHolder getViewHolder(View v) {
        ViewHolder mViewHolder = new ViewHolder();
        mViewHolder.iv_icon = (ImageView) v.findViewById(R.id.iv_icon);
        mViewHolder.tv_icon = (TextView) v.findViewById(R.id.tv_icon);
        v.setTag(mViewHolder);
        return mViewHolder;
    }

    private void setData(int position, ViewHolder viewHolder) {
    }

    public static class ViewHolder {
        public ImageView iv_icon;
        public TextView tv_icon;
    }
}
